<script language="javascript">    
    //Number
    (function($){        
        $(document).ready(function() {
            $("#search").submit(function(e) {                
                var invalid_number = false;                
                var element_val = $("#maxprice").val();
                if(element_val != '') {            
                    var reg_number = /^[0-9]*$/;
                    if(!reg_number.test(element_val))
                        invalid_number = true;

                    var next_element = $("#maxprice").parent();
                    $(next_element).find('div.error').remove();
                }

                if(invalid_number) {
                    $("#maxprice").css('border-color', 'red');
                    $(next_element).append('<div class="error">Invalid number</div>');                        
                }
                else 
                    $(this).css('border', '1px solid #DADADA');

                if(invalid_number)
                    e.preventDefault();
            }); 
        });
    })(jQuery);
</script>
<div id="content">
    <div class="container_medium">
<?php 
        echo form_open(base_url()."index.php/buy/result", array ('id'=>'search')); 
?>
	<h1 class="blue">Find New & Used Cars</h1>
        <table class="table_advance">
            <tbody>
                <tr>
                    <td>Type</td>
                    <td>&nbsp;</td>
                    <td>Reference number</td>
                </tr>
                <tr>
                    <td>
                        <select name="cartype">
                            <option value="%">Please select</option>
<?php 
            foreach($type->result() as $row)
            {        	
?>
                            <option value="<?php echo $row->code; ?>">
<?php 
                                echo $row->name 
?>
                            </option>              
<?php
            }
?>        
                        </select>                        
                    </td>
                    <td>&nbsp;</td>
                    <td> 
                        <input type="text" name="reference_number" value="" />
                    </td>
                </tr>
                <tr>
                    <td>Make</td>
                    <td>&nbsp;</td>
                    <td>Location</td>
                </tr>
                <tr>
                    <td>
                        <select name="make" id="make">
                            <option value="">Please select</option>
<?php 
            foreach($make->result() as $row)
            { 
?>
                            <option value="<?php echo $row->id; ?>">
<?php 
                                echo $row->name;
?>
                            </option>
<?php
            }
?>        
                        </select>                        
                    </td>
                    <td>&nbsp;</td>
                    <td>
<select name="location">
                            <option value="">Please select</option>
<?php 
            foreach($location->result() as $row)
            { 
?>
                            <option>
<?php 
                                echo $row->province 
?>
                            </option>
<?php
            }
?>    
                        </select>                        
                    </td>
                </tr>
                <tr>
                    <td>Model</td>
                    <td>&nbsp;</td>
                    <td>Dealer</td>
                </tr>
                <tr>
                    <td>
                        <select name="model" id="model">
                            <option value="">Please select</option>
                        </select>
                    </td>
                    <td>&nbsp;</td>
                    <td>
            <select name="dealer">
                <option value="">Please select</option>
<?php 
            foreach($dealer->result() as $row)
            { 
?>
                <option>
<?php 
                    echo $row->company;
?>
                </option>
<?php
            }
?>    
            </select>                             
                    </td>
                </tr>
                <tr>
                    <td>Maximum Price</td>
                    <td>&nbsp;</td>
                    <td></td>
                </tr>
                <tr>
                    <td>
                        <input type="text" name="maxprice" class="number" id="maxprice" />
                    </td>
                    <td>&nbsp;</td>
                    <td>                   
                    </td>
                </tr>                
                <tr>
                    <td colspan="3">
<?php
                        echo form_submit(array ('name'=>'search', 'class'=>'btnsearch'), '');
?>
                    </td>
                </tr>
            </tbody>
        </table>
<?php         
        echo form_close();
?>
    </div>

    <div class="quicklink">
<?php 
        $this->load->view('/templates/quicklinks');
?>
    </div>
</div>
<div class="separator"></div>